#pragma once

#include <websocketpp/config/asio_client.hpp>
#include <websocketpp/client.hpp>
#include <iostream>
#include <cstring>
#include <thread>
#include <map>
#include <set>
#include <curl/curl.h>
#include <openssl/hmac.h>
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <openssl/buffer.h>
#include <nlohmann/json.hpp>
#include "fmtlog.h"
#include "object.h"

using client = websocketpp::client<websocketpp::config::asio_tls_client>;
using context_ptr = std::shared_ptr<boost::asio::ssl::context>;
using websocketpp::lib::bind;
using websocketpp::lib::placeholders::_1;
using message_ptr = websocketpp::config::asio_client::message_type::ptr;

class BinanceTrade {
public:
    static BinanceTrade* getInstance(const std::string &api_key,const std::string &secret_key);
    std::string getSignature(const std::string& data);
    std::string UnixTimestampMills();
    void place_order(const Order &ord);
    void connect();

protected:
    void run_trade_client();
    void on_trade_message(websocketpp::connection_hdl hdl, message_ptr msg);
    void on_trade_open(websocketpp::connection_hdl hdl);
    void on_trade_close(websocketpp::connection_hdl hdl);

private:
    client m_trade_client;
    websocketpp::connection_hdl handle_;

    std::string apiKey;
    std::string secretKey; 
    std::string tradeUrl = "wss://ws-api.binance.com:443/ws-api/v3";

    static BinanceTrade* tradeHandler;
    BinanceTrade(const std::string &api_key,const std::string &secret_key);
};